function ajajform_dialog(dialogoptions,frmoptions,widgets)
{
	var frm;
	var id=0;
	while ($("#dialogdiv"+id).length) id++;
	var tmp1=$("<div id='dialogdiv"+id+"'></div>").appendTo($("body"));
	dialogoptions.id="dialogdiv"+id;
	if (dialogoptions.lefthtml) {
		$("<table border='0' cellspacing='0' cellpadding='0'><tr><td valign='top' class='lefthtml'></td><td valign='top'><div id='dialogfrm"+id+"'></div></td></tr></table>").appendTo(tmp1);
		$(".lefthtml",tmp1).html(dialogoptions.lefthtml);
	} else {
		$("<div id='dialogfrm"+id+"'></div>").appendTo(tmp1);
	}
	var submited=0;
	var ddiv=$('#dialogdiv'+id);
	ddiv.dialog({
		title: dialogoptions.title,
		close: function(event, ui) {
			if (!submited && dialogoptions.close) dialogoptions.close(dialogoptions.data);
			ddiv.remove();
		},
		width: dialogoptions.width||500,
		modal: true
	});
	var fopt={};
	for (var k in frmoptions) fopt[k]=frmoptions[k];
	fopt.submit={
		value:dialogoptions.submit.value,
		params:dialogoptions.submit.params
	};
	if (dialogoptions.submit.click) {
		fopt.submit.click=function(r,r2) {
//			console.log("Submit clicked");
			if (dialogoptions.submit.click(r,r2)) {
//				console.log("Submit function ok");
				submited=true;
//				console.log("Removing div");
				ddiv.remove();
			}
			return false;
		};
	}
	fopt.name="dialogfrm"+id;
	var frm=$("#dialogfrm"+id).ajajform(fopt);
	for (var i=0;i<widgets.length;i++) {
		frm.ajajform("insertWidget",null,null,widgets[i]);
	}
	return frm;
}

function html_dialog(dialogoptions,html)
{
	var id=0;
	while ($("#dialogdiv"+id).length) id++;
	dialogoptions.id="dialogdiv"+id;
	var tmp1=$("<div id='dialogdiv"+id+"'></div>").appendTo($("body"));
	tmp1.html(html);	
	var submited=0;
	var ddiv=$('#dialogdiv'+id);
	ddiv.dialog({
		title: dialogoptions.title,
		close: function(event, ui) {
			if (!submited && dialogoptions.close) dialogoptions.close(dialogoptions.data);
			ddiv.remove();
		},
		width: dialogoptions.width||500,
		height: dialogoptions.height,
		modal: true
	});
}
